import VueRouter from "vue-router";
import Vue from "vue";
import Layout from "@/layout/index.vue";
import nestedRouter from './modules/nested.js'
Vue.use(VueRouter);

/**通用页面 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta:{
      menuInHidden: true,
    }
  },
  {
    path: "/",
    redirect: "/dashboard",
    component: Layout,
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        meta: { title: "首页", icon: "menu" , affix: true },
        component: () => import("@/views/dashboard/index.vue"),
      },
    ],
  },
  {
    path: "/news",
    redirect: "/news/index",
    component: Layout,
    children: [
      {
        path: "index",
        name: "News",
        meta: { title: "新闻", icon: "location", menuInHidden: true },
        component: () => import("@/views/news/index.vue"),
      },
    ],
  },
  {
    path: "/guide",
    component: Layout,
    redirect: "/guide/index",
    children: [
      {
        path: "index",
        name: "Guide",
        meta: { title: "引导", icon: "setting" },
        component: () => import("@/views/guide/index"),
      },
    ],
  },
];

/**
 * 权限页面
 * v3 版本中提供额 addRoute 方法来动态添加路由
 * 注意： 404 页面要放在最后
 */
export const asyncRoutes = [
  {
    path: "/permission",
    component: Layout,
    redirect: "/permission/page",
    name: "Permission",
    meta: {
      title: "Permission",
      icon: "lock",
      roles: ["admin", "editor"], // you can set roles in root nav
    },
    children: [
      {
        path: "page",
        component: () => import("@/views/permission/page.vue"),
        name: "PagePermission",
        meta: {
          title: "Page Permission",
          roles: ["admin"], // or you can only set roles in sub nav
        },
      },
      {
        path: "role",
        component: () => import("@/views/permission/role.vue"),
        name: "RolePermission",
        meta: {
          title: "Role Permission",
          roles: ["admin"],
        },
      },
    ],
  },

  { path: "*", redirect: "/404", hidden: true },
];

export const routes = [...constantRoutes, nestedRouter ];

const router = new VueRouter({
  mode: "history",
  routes,
});

export default router;
